ng-book 2 by Felipe Coury Ari Lerner Nate Murray && Carlos Taborda

ng-book 2 by Felipe Coury Ari Lerner Nate Murray && Carlos Taborda

Author:Felipe Coury, Ari Lerner, Nate Murray, && Carlos Taborda
Language: eng
Format: mobi
Publisher: leanpub.com
Published: 2016-09-02T04:00:00+00:00


One other detail, since we’re already looking that the messages for the current thread, this is a convenient area to mark these messages as read.

code/rxjs/chat/app/ts/services/ThreadsService.ts 54 return _.chain(messages) 55 .filter((message: Message) => 56 (message.thread.id === currentThread.id)) 57 .map((message: Message) => { 58 message.isRead = true; 59 return message; }) 60 .value();

Whether or not we should be marking messages as read here is debatable. The biggest drawback is that we’re mutating objects in what is, essentially, a “read” thread. i.e. this is a read operation with a side effect, which is generally a Bad Idea. That said, in this application the currentThreadMessages only applies to the currentThread and the currentThread should always have its messages marked as read. That said, the “read with side-effects” is not a pattern I recommend in general.

Putting it together, here’s what currentThreadMessages looks like:

code/rxjs/chat/app/ts/services/ThreadsService.ts 50 this.currentThreadMessages = this.currentThread 51 .combineLatest(messagesService.messages, 52 (currentThread: Thread, messages: Message[]) => { 53 if (currentThread && messages.length > 0) { 54 return _.chain(messages) 55 .filter((message: Message) => 56 (message.thread.id === currentThread.id)) 57 .map((message: Message) => { 58 message.isRead = true; 59 return message; }) 60 .value(); 61 } else { 62 return []; 63 } 64 });



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.